package com.example.sqldemo.cursor;

import com.example.sqldemo.mapper.SqlMapper;
import org.apache.ibatis.cursor.Cursor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.Iterator;

public abstract class AbstractState implements State {

    @Autowired
    private SqlMapper sqlMapper;

    @Transactional
    public void process() {
        sqlMapper.createTable3();
        Cursor<HashMap<String, Object>> data = getData();
        Iterator<HashMap<String, Object>> iterator = data.iterator();
        while (iterator.hasNext()) {
            HashMap<String, Object> next = iterator.next();
            System.out.println(next);
        }
    }

    protected abstract Cursor<HashMap<String, Object>> getData();
}
